import { getToken, setToken, removeToken } from "@/utils/auth"
export default {
    namespaced: 'user',
    state: () => ({
        token: getToken(),
        userInfo: {},
    }),
    mutations: {
        setToken(state, token) {
            state.token = token
            setToken(token)
        },
        setUserInfo(state, userInfo) {
            state.userInfo = userInfo
        }
    },
    actions: {
        setUserInfo({ commit } , userInfo) {
            commit('setUserInfo', userInfo)
            commit('setToken', userInfo.token)
        },
        logout({ commit, state }) {
            commit('setToken', '')
            commit('setUserInfo', {})
            removeToken()
            location.reload(true)
        }
    }
}